<template>
  <!-- 工时维护店端-经销商端页面 -->
  <div>
    <!--条件筛选-->
    <TopFilter :list="topFilterList" :cols="3" labelWidth="85" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!--操作 -->
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <!-- 列筛选-->
    <FilterTable
      ref="table"
      columnsRef="repair-labourHour-index"
      :selectionType="selectionType"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectData"
    >
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">关 闭</el-button>
      <AjaxButton type="primary" :click="saveDialog">保 存</AjaxButton>
    </div>
  </div>
</template>

<script>
import { getSeriesModelBrandList } from '@/api/repair/repairBusiness/labourHour/index.js';
export default {
  props: {
    selectionType: {
      type: String,
      default: 'multiple'
    }
  },
  data() {
    this.saveData = null;
    return {
      topFilterList: this.createTopFilterList(),
      columns: this.createTableColumns(),
      fetchApi: getSeriesModelBrandList,
      fetchParams: { xhrAbort: false },
      tableData: []
    };
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '品牌',
          fieldName: 'brandName'
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'modelName'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '品牌',
          dataIndex: 'brandName',
          sorter: true
        },
        {
          title: '车系代码',
          dataIndex: 'seriesCode',
          sorter: true
        },
        {
          title: '车系名称',
          dataIndex: 'seriesName',
          sorter: true
        },
        {
          title: '车型代码',
          dataIndex: 'modelCode',
          sorter: true
        },
        {
          title: '车型名称',
          dataIndex: 'modelName',
          sorter: true
        }
      ];
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    selectData(val) {
      this.tableData = val;
    },
    saveDialog() {
      this.$emit('close', this.tableData);
    },
    closeDialog(param) {
      this.$emit('close');
    }
  }
};
</script>
